import { useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import Creator from "../store/actions";
// 引入api
import TypesApi from "../api/types";

export const useAllTypes = () => {
    // 获取全部父类型数据
    const allType = useSelector(state => {
        return state.allType
    })
    const dispatch = useDispatch();
    // 操作状态的行为
    // 获取所有父类型
    const getAllTypes = useCallback(async () => {
        const data = await TypesApi.getTypes()
        dispatch(Creator.getAllTypes({data}));
    }, [dispatch]);

    return [allType, { getAllTypes}]

}